<!DOCTYPE html>
<html><head>
        <meta charset="utf-8">
    <title>shop</title>

    <meta name="description" content="Dashboard">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!--Basic Styles-->
    <link href="__ADMIN__/style/bootstrap.css" rel="stylesheet">
    <link href="__ADMIN__/style/font-awesome.css" rel="stylesheet">
    <link href="__ADMIN__/style/weather-icons.css" rel="stylesheet">

    <!--Beyond styles-->
    <link id="beyond-link" href="__ADMIN__/style/beyond.css" rel="stylesheet" type="text/css">
    <link href="__ADMIN__/style/demo.css" rel="stylesheet">
    <link href="__ADMIN__/style/typicons.css" rel="stylesheet">
    <link href="__ADMIN__/style/animate.css" rel="stylesheet">
     <script src="__PLUS__/ueditor/ueditor.config.js"></script>
    <script src="__PLUS__/ueditor/ueditor.all.min.js"></script>
    <script src="__PLUS__/ueditor/lang/zh-cn/zh-cn.js"></script>
<style type="text/css">
 .price{display:inline-block;width:200px;}

</style>
</head>
<body>
    <!-- 头部 -->
{include file="common/top"}
    <!-- /头部 -->

    <div class="main-container container-fluid">
        <div class="page-container">
                        <!-- Page Sidebar -->
            {include file="common/left"}
            <!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                                        <li>
                        <a href="{:url('Index/index')}">系统</a>
                    </li>
                      <li>
                        <a href="{:url('Goods/lst')}">商品列表</a>
                    </li>
                    <li class="active">修改商品</li>
                    </ul>
                </div>
                <!-- /Page Breadcrumb -->

                <!-- Page Body -->
                <div class="page-body">

<div class="row">
    <div class="col-lg-12 col-sm-12 col-xs-12">
        <div class="widget">
            <form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data" >
            <input type="hidden" name="id" value="{$goods.id}"/>
            <input type="hidden" name="og_thumb" value="{$goods.og_thumb}"/>
            <input type="hidden" name="big_thumb" value="{$goods.big_thumb}"/>
            <input type="hidden" name="mid_thumb" value="{$goods.mid_thumb}"/>
            <input type="hidden" name="sm_thumb" value="{$goods.sm_thumb}"/>
            <!-- 商品信息开始 -->
            <div class="widget-body">
                <div class="widget-main ">
                    <div class="tabbable">
                        <ul class="nav nav-tabs tabs-flat" id="myTab11">
                            <li class="active">
                                <a data-toggle="tab" href="#baseinfo">
                                    商品基本信息
                                </a>
                            </li>
                            <li>
                                <a data-toggle="tab" href="#goodsdes">
                                    描述信息
                                </a>
                            </li>
                             <li>
                                <a data-toggle="tab" href="#mbprice">
                                    会员价格
                                </a>
                            </li>
                            <li>
                            <li>
                                <a data-toggle="tab" href="#goodsattr">
                                    商品属性
                                </a>
                            </li>
                            <li>
                                <a data-toggle="tab" href="#goodsphoto">
                                    商品相册
                                </a>
                            </li>
                        </ul>
                        <div class="tab-content tabs-flat">
                            <div id="baseinfo" class="tab-pane in active">
                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">商品名称</label>
                                    <div class="col-sm-6">
                                        <input class="form-control"  placeholder="" name="goods_name" value="{$goods.goods_name}" required="" type="text">
                                    </div>
                                    <p class="help-block col-sm-4 red">* 必填</p>
                                </div>
                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">推荐位</label>
                                    <div class="col-sm-6">

                                        <div class="checkbox">
                                        {volist name="goodsRecposRes" id="rec"}
                                            <label style="margin-right: 10px;">
                                                <?php
                                                    if (in_array($rec['id'],$mygoodsRecposRes)) {
                                                            $checked='checked="checked"';
                                                    }else{
                                                        $checked='';
                                                    }
                                                ?>
                                                <input type="checkbox" name="recpos[]" <?php echo $checked; ?> value="{$rec.id}" class="colored-blue" >
                                                <span class="text">{$rec.rec_name}</span>
                                            </label>
                                        {/volist}
                                        </div>

                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">商品主图</label>
                                    <div class="col-sm-6">
                                        <input  name="og_thumb" type="file" style="margin-top:5px">
                                        {if condition="$goods['og_thumb'] neq '' "}
                                        <img src="__uploads__/{$goods.og_thumb}" alt="" height="50">
                                        {else/}
                                            暂无图片
                                        {/if}
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">上架</label>
                                    <div class="col-sm-6">
                                        <!-- 单选 -->
                                        <div class="radio" style="float: left; padding-right: 15px;">
                                        <label>
                                            <input name="on_sale" {if condition="$goods['on_sale'] eq 1"}checked="checked"{/if}  class="colored-blue" value="1" type="radio">
                                            <span class="text">是 </span>
                                        </label>
                                        </div>
                                        <div class="radio" style="float: left; padding-right: 15px;">
                                        <label>
                                            <input name="on_sale"  {if condition="$goods['on_sale'] eq 0"}checked="checked"{/if}  class="colored-blue" value="0" type="radio">
                                            <span class="text">否 </span>
                                        </label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">所属栏目</label>
                                    <div class="col-sm-6">
                                        <select name="category_id" >
                                            <option value="">请选择</option>
                                            {volist name="categoryRes" id="cate"}
                                            <option  value="{$cate.id}" {if condition="$goods['category_id'] eq $cate['id']"}selected="selected"{/if}> <?php echo str_repeat('-', $cate['level']*8)?>{$cate.cate_name}</option>
                                            {/volist}
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">所属品牌</label>
                                    <div class="col-sm-6">
                                        <select name="brand_id" >
                                            <option value="">请选择</option>
                                            {volist name="brandRes" id="brand"}
                                            <option value="{$brand.id}" {if condition="$goods['brand_id'] eq $brand['id']"}selected="selected"{/if}>{$brand.brand_name}</option>
                                            {/volist}
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">市场价</label>
                                    <div class="col-sm-6">
                                        <input class="form-control"  placeholder="" name="markte_price" value="{$goods.markte_price}" type="text">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">本店价</label>
                                    <div class="col-sm-6">
                                        <input class="form-control" name="shop_price" value="{$goods.shop_price}" type="text">
                                    </div>

                                </div>
                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">重量</label>
                                    <div class="col-sm-6">
                                        <input class="form-control"  style="width: 200px; display: inline-block;"  name="goods_weight"  value="{$goods.goods_weight}" type="text">
                                        <select name="weight_unit" >
                                            <option value="kg" {if condition="$goods['weight_unit'] eq 'kg'"}selected="selected"{/if}>kg</option>
                                            <option value="g" {if condition="$goods['weight_unit'] eq 'g'"}selected="selected"{/if}>g</option>
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div id="goodsdes" class="tab-pane">
                                <textarea name="goods_des" id="goods_des">{$goods.goods_des}</textarea>
                            </div>
                            <div id="mbprice" class="tab-pane">

                                {volist name="mlRes" id="ml"}

                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right">{$ml.level_name}</label>
                                    <div class="col-sm-6">
                                        <input class="form-control"  placeholder="" name="mp[{$ml.id}]" value="<?php if (isset($mpRes[$ml['id']]['mprice'])) {
                                        echo $mpRes[$ml['id']]['mprice']; }else{ echo '';} ?>"  type="text">
                                    </div>
                                </div>
                                {/volist}

                            </div>
                            <div id="goodsattr" class="tab-pane">
                                <div class="form-group">
                                        <label for="username" class="col-sm-2 control-label no-padding-right">商品类型</label>
                                        <div class="col-sm-6">
                                            <select name="type_id" disabled="disabled">
                                                <option value="0">请选择</option>
                                                {volist name="typeRes" id="type"}
                                                <option value="{$type.id}" {if condition=" $goods['type_id'] eq $type['id']"} selected="selected" {/if}>{$type.type_name}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>
                                <div id='attr_list'>
                                <?php  foreach($attrRes as $k=>$v):?>
                                    <?php if($v['attr_type']==1)  :?>
                                        <?php
                                            $arrRido=explode(',',$v['attr_values'])
                                        ?>
                                        <!-- 循环当前商品拥有的属性开始 -->
                                        <?php  foreach($gattrRes[$v['id']] as $k0=>$v0):?>
                                        <div  gaid="<?php echo $v0['id']?>" class="form-group">
                                            <label class="col-sm-2 control-label no-padding-right"><?php echo $v['attr_name']?></label>
                                            <div class="col-sm-6">
                                            <a class="abtn" onclick="addrow(this);" href="#">[<?php if( $k0 == 0){echo '+';}else{echo '-';} ?>]</a>
                                            <select name='old_goods_attr[<?php echo $v['id']?>][]'>
                                              <option value="">请选择</option>
                                             <?php  foreach($arrRido as $k1=>$v1):?>
                                              <option <?php if ($v1 == $v0['attr_value']) { echo 'selected="selected"' ;} ?>  value="<?php echo $v1?>"><?php echo $v1?></option>
                                              <?php endforeach;?>
                                            </select>
                                            <input class="form-control price" placeholder="价格" name="old_attr_price[<?php echo $v0['id']?>]" value="<?php echo $v0['attr_price'] ?>" type="text">
                                            </div>
                                        </div>
                                      <?php endforeach ;?>
                                        <!-- 循环当前商品拥有的属性结束 -->
                                    <?php else :?>
                                        <!-- 唯一 -->
                                        <?php if( !$v['attr_values']):?>
                                            <div class="form-group">
                                              <label class="col-sm-2 control-label no-padding-right"><?php echo $v['attr_name']?></label>
                                              <div class="col-sm-6">
                                                <input class="form-control price" name="old_goods_attr[<?php echo $v['id']?>]" type="text" value="<?php echo $gattrRes[$v['id']][0]['attr_value']?>" >
                                                <input type="hidden" name="old_attr_price[<?php echo $gattrRes[$v['id']][0]['id']?>]" />
                                              </div>
                                            </div>
                                        <?php else :?>
                                           <div class="form-group">
                                                <label for="username" class="col-sm-2 control-label no-padding-right"><?php echo $v['attr_name']?></label>
                                                <div class="col-sm-6">
                                                <?php
                                                    $arrSelect=explode(',',$v['attr_values'])
                                                ?>
                                                    <select name="old_goods_attr[<?php echo $v['id']?>]">
                                                        <option value="0">请选择</option>
                                                       <?php  foreach($arrSelect as $k1=>$v1):?>
                                                      <option <?php if ($v1 == $gattrRes[$v['id']][0]['attr_value']) { echo 'selected="selected"' ;} ?> value="<?php echo $v1?>"><?php echo $v1?></option>
                                                      <input type="hidden" name="old_attr_price[<?php echo $gattrRes[$v['id']][0]['id']?>]" />
                                                      <?php endforeach;?>
                                                    </select>
                                                </div>
                                            </div>
                                        <?php endif;?>

                                    <?php endif;?>
                                <?php endforeach;?>
                                </div>

                            </div>
                            <div id="goodsphoto" class="tab-pane">
                              {volist name="gphotoRes" id="gphoto"}
                                <div class="form-group" id="{$gphoto.id}">
                                    <label for="username" class="col-sm-2 control-label no-padding-right"></label>
                                    <div class="col-sm-6">
                                        <a href="#" onclick="delrow(this);">[-]</a>
                                        <img src="__uploads__/{$gphoto.sm_photo}" alt="" style="height: 50px;   display:inline-block;">
                                    </div>
                                </div>
                                {/volist}
                                <div class="form-group">
                                    <label for="username" class="col-sm-2 control-label no-padding-right"></label>
                                    <div class="col-sm-6">
                                        <a href="#" onclick="addrow(this);">[+]</a><input class="form-control" style="border:none; box-shadow:none; width:50%; display:inline-block;" name="goods_photo[]" type="file">
                                    </div>
                                </div>
                                <div id="goods_photo"></div>
                            </div>

                        </div>
                    </div>
                </div>
                <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" class="btn btn-default">保存信息</button>
                </div>
            </div>
            <!-- 商品信息结束 -->
            </form>
        </div>
    </div>
</div>

                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->
        </div>
    </div>

        <!--Basic Scripts-->
    <script src="__ADMIN__/style/jquery_002.js"></script>
    <script src="__ADMIN__/style/bootstrap.js"></script>
    <script src="__ADMIN__/style/jquery.js"></script>
    <!--Beyond Scripts-->
    <script src="__ADMIN__/style/beyond.js"></script>
      <script type="text/javascript">

        //实例化编辑器
        //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
        UE.getEditor('goods_des',{initialFrameWidth:1200,initialFrameHeight:800,});

    </script>

   <script type="text/javascript">
    $("select[name=type_id]").change(function(){
        var type_id=$(this).val();
        $.ajax({
            type:"POST",
            url:"{:url('Attr/ajaxGetAttr')}",
            data:{type_id:type_id},
            dataType:"json",
            success:function(data){
                // console.log(data);
                var html="";
                $(data).each(function(k,v){
                    if(v.attr_type == 1){
                        // 单选处理
                        html+="<div class='form-group'>";
                        html+="<label class='col-sm-2 control-label no-padding-right'>"+v.attr_name+"</label>";
                        var attrValuesArr=v.attr_values.split(",");
                        html+="<div class='col-sm-6'><a class='abtn' onclick='addrow(this);' href='#'>[+]</a>";
                        html+="<select name='goods_attr["+v.id+"][]'>";
                        html+="<option value=''>请选择</option>";
                        for(var i=0; i<attrValuesArr.length; i++){
                            html+="<option value='"+attrValuesArr[i]+"'>"+attrValuesArr[i]+"</option>";
                        }
                        html+="</select>";
                        html+="<input class='form-control price' placeholder='价格' name='attr_price[]' type='text'>";
                        html+="</div></div>";

                    }else{
                        // 唯一处理
                        if(v.attr_values){
                            html+="<div class='form-group'>";
                            html+="<label class='col-sm-2 control-label no-padding-right'>"+v.attr_name+"</label>";
                            var attrValuesArr=v.attr_values.split(",");
                            html+="<div class='col-sm-6'>";
                            html+="<select name=goods_attr["+v.id+"]>";
                            html+="<option value=''>请选择</option>";
                            for(var i=0; i<attrValuesArr.length; i++){
                                html+="<option value='"+attrValuesArr[i]+"'>"+attrValuesArr[i]+"</option>";
                            }
                            html+="</select>";
                            html+="</div></div>";
                        }else{
                            html+="<div class='form-group'>";
                            html+="<label class='col-sm-2 control-label no-padding-right'>"+v.attr_name+"</label>";
                            var attrValuesArr=v.attr_values.split(",");
                            html+="<div class='col-sm-6'>";
                            html+="<input class='form-control price' name=goods_attr["+v.id+"] type='text'>";
                            html+="</div></div>";
                        }
                    }
                });
                $("#attr_list").html(html);
            }
        });
    });

    function addrow(o){
        var div=$(o).parent().parent();
        if($(o).html() == '[+]'){
            var newdiv=div.clone();
            newdiv.find('a').html('[-]');
            //修改old_attr_price[]为attr_price[]
            newdiv.find(':text').attr('name','attr_price[]');
            //修改old_goods_attr[][]为goods_attre[][]
            var sel=newdiv.find('select');
            var oldname=sel.attr('name');
            var newname=oldname.replace('old_','');
            sel.attr('name',newname);
            div.after(newdiv);
        }else{
            if (confirm('确定删除该属性吗？')) {
             var div=$(o).parent().parent();
             var gaid=div.attr('gaid');
              $.ajax({
                type:"POST",
                data:{gaid:gaid},
                url:"{:url('GoodsAttr/ajaxdelga')}",
                success:function(data){

                    if (data==1) {
                        div.remove();
                    }else{
                        alert('删除失败');
                    }
                }

              });

            };
        }
    }

    function delrow(o){
        if (confirm('确定删除该图吗？')) {
         var div=$(o).parent().parent();
         var id=div.attr('id');

          $.ajax({
            type:"POST",
            data:{id:id},
            url:"{:url('Goods/ajaxdelpic')}",
            success:function(data){
                if (data==1) {
                    div.remove();
                }else{
                    alert('删除失败');
                }
            }

          });


        };

    }
    </script>
</body></html>